//
//  userInfoVC.m
//  qulvyou
//
//  Created by mmyy on 15/10/23.
//  Copyright (c) 2015年 mmyy. All rights reserved.
//

#import "userInfoVC.h"

#import "userxiangqingItems.h"

#import "jincaCell.h"

#import "tripsItems.h"

#import "xinchengVC.h"

@interface userInfoVC ()<UITableViewDataSource, UITableViewDelegate>

@end

@implementation userInfoVC
{
    UITableView *_tableView;
    userxiangqingItems *_items;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor purpleColor];
    self.navigationItem.title = @"游记";
    [self loadData];
    // Do any additional setup after loading the view.
}
-(void)loadData
{
    [Funcation getWithURL:[NSString stringWithFormat:userInfoUrl, self.userId] success:^(id responseObject) {
        NSDictionary *data = [responseObject objectForKey:@"data"];
        _items = [userxiangqingItems userxiangqingItemsWithDict:data];
        [self createTableView];
    } andFail:^(id error) {
        
    }];
}
-(void)createTableView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 65, self.view.frame.size.width, self.view.frame.size.height - 65) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.separatorColor = [UIColor clearColor];
    _tableView.rowHeight = 180;
    _tableView.allowsSelection = NO;
    [self.view addSubview:_tableView];
    [self createHeadView];
    
}
-(void)createHeadView
{
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 240)];
    UIImageView *headImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180)];
    [headImage setImageWithURL:[NSURL URLWithString:_items.cover]];
    [headView addSubview:headImage];
    UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180)];
    blackView.backgroundColor = [UIColor blackColor];
    blackView.alpha = 0.2;
    [headImage addSubview:blackView];
    UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, self.view.frame.size.width, 30)];
    name.text = _items.name;
    name.textColor = [UIColor whiteColor];
    name.font = [UIFont boldSystemFontOfSize:22];
    name.textAlignment = NSTextAlignmentCenter;
    name.backgroundColor = [UIColor clearColor];
    [headView addSubview:name];
    
    UIImageView *aval = [[UIImageView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 60) / 2.0, 50, 60, 60)];
    [aval setImageWithURL:[NSURL URLWithString:_items.avatar_l]];
    aval.layer.cornerRadius = 30;
    aval.layer.masksToBounds = YES;
    [headView addSubview:aval];
    
    UILabel *guangzhu = [[UILabel alloc] initWithFrame:CGRectMake(0, 120, self.view.frame.size.width, 20)];

    
    guangzhu.text = [NSString stringWithFormat:@"关注%@ / 粉丝%@", _items.followers_count, _items.followings_count];
    guangzhu.textColor = [UIColor whiteColor];
    guangzhu.font = [UIFont systemFontOfSize:15];
    guangzhu.textAlignment = NSTextAlignmentCenter;
    guangzhu.backgroundColor = [UIColor clearColor];
    [headView addSubview:guangzhu];
    
    
    UILabel *youji = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, self.view.frame.size.width, 30)];
    
    
    youji.text = [NSString stringWithFormat:@"-------%lu游记---------", (unsigned long)_items.trips.count];
    youji.textColor = [UIColor darkGrayColor];
    youji.font = [UIFont boldSystemFontOfSize:20];
    youji.textAlignment = NSTextAlignmentCenter;
    youji.backgroundColor = [UIColor clearColor];
    [headView addSubview:youji];
    
    
    _tableView.tableHeaderView = headView;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _items.trips.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ident = @"basis_cell";
    jincaCell *cell = [tableView dequeueReusableCellWithIdentifier:ident];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"jincaCell" owner:nil options:nil] firstObject];
    }
    cell.backgroundColor = [UIColor clearColor];
    tripsItems *items = [_items.trips objectAtIndex:indexPath.row];
    
    [cell.cover_image setImageWithURL:[NSURL URLWithString:items.cover_image] placeholderImage:[UIImage imageNamed:@"define"]];

    
    cell.cover_image.layer.cornerRadius = 10;
    cell.cover_image.layer.masksToBounds = YES;
//    cell.cover_image.userInteractionEnabled = YES;
//    cell.cover_image.tag = indexPath.row + 10;
    cell.name.text = items.name;
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
//    [cell.cover_image addGestureRecognizer:tap];
    return cell;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
